package com.leetcode.LC;

import java.util.HashSet;

public class LC1496 {
    public boolean isPathCrossing(String path) {

        int[] ints = {0, 0};
        HashSet<String> set = new HashSet<>();
        set.add(ints[0] + "" + ints[1] + "");
        for (int i = 0; i < path.length(); i++) {
            if (path.charAt(i) == 'N') {
                ints[1] += 1;
            } else if (path.charAt(i) == 'E') {
                ints[0] += 1;
            } else if (path.charAt(i) == 'S') {
                ints[1] -= 1;
            } else if (path.charAt(i) == 'W') {
                ints[0] -= 1;
            }
            if (set.contains(ints[0] + "" + ints[1] + "")){
                return true;
            }else {
                set.add(ints[0] + "" + ints[1] + "");
            }
        }
        return false;
    }

    public static void main(String[] args) {
        System.out.println(new LC1496().isPathCrossing("NESWW"));
    }
}
